const config = require('../config');
const attestationApi = config.attestationApi.url;
const axios = require('axios');
const { IndexedTx,SigningStargateClient, StargateClient } = require("@cosmjs/stargate")
const { decodeTxRaw } = require('@cosmjs/proto-signing')
const Web3 = require('web3');
const web3 = new Web3();
const { MsgReceiveMessage } = require("../generated/circle/cctp/v1/tx")
const error_txHash1= "71782FB73090479DFF831430E4EE9C62BFE991F01F2E31D1F3D4299BE4E1A1BB"
const error_txHash2 = "A3990BB0BDE7E8BDF691C77B53CED7C9745ADCE002C5C8F490D889D49739FBE3"
const run = async ()=>{

    const rpc = config.noble.url;

    const client = await StargateClient.connect(rpc)
    let tx = await client.getTx(error_txHash2)
    //console.log('tx: ',tx.tx);

    let rawTx = tx.tx;
    let decodedTx = decodeTxRaw(rawTx);
    //console.log("decodedTx: ", decodedTx);
    let messages = decodedTx.body.messages;
    for(let message of messages) {
        console.log("message ", message);
        let m = MsgReceiveMessage.decode(message.value)
        console.log('m: ',m);
        console.log("m.address:", m.from)
        console.log("m.message",Buffer.from(m.message).toString('base64'))
        console.log("m.attestation",Buffer.from(m.attestation, 'utf-8').toString('base64'))
    }

}

run();